<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>claed0.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="CLAED0.1"></a><a href="claed0.f.html#CLAED0.1">CLAED0</a>( QSIZ, N, D, E, Q, LDQ, QSTORE, LDQS, RWORK,
     $                   IWORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            INFO, LDQ, LDQS, N, QSIZ
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      INTEGER            IWORK( * )
      REAL               D( * ), E( * ), RWORK( * )
      COMPLEX            Q( LDQ, * ), QSTORE( LDQS, * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Using the divide and conquer method, <a name="CLAED0.20"></a><a href="claed0.f.html#CLAED0.1">CLAED0</a> computes all eigenvalues
</span><span class="comment">*</span><span class="comment">  of a symmetric tridiagonal matrix which is one diagonal block of
</span><span class="comment">*</span><span class="comment">  those from reducing a dense or band Hermitian matrix and
</span><span class="comment">*</span><span class="comment">  corresponding eigenvectors of the dense or band matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  QSIZ   (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The dimension of the unitary matrix used to reduce
</span><span class="comment">*</span><span class="comment">         the full matrix to tridiagonal form.  QSIZ &gt;= N if ICOMPQ = 1.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N      (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The dimension of the symmetric tridiagonal matrix.  N &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  D      (input/output) REAL array, dimension (N)
</span><span class="comment">*</span><span class="comment">         On entry, the diagonal elements of the tridiagonal matrix.
</span><span class="comment">*</span><span class="comment">         On exit, the eigenvalues in ascending order.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  E      (input/output) REAL array, dimension (N-1)
</span><span class="comment">*</span><span class="comment">         On entry, the off-diagonal elements of the tridiagonal matrix.
</span><span class="comment">*</span><span class="comment">         On exit, E has been destroyed.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Q      (input/output) COMPLEX array, dimension (LDQ,N)
</span><span class="comment">*</span><span class="comment">         On entry, Q must contain an QSIZ x N matrix whose columns
</span><span class="comment">*</span><span class="comment">         unitarily orthonormal. It is a part of the unitary matrix
</span><span class="comment">*</span><span class="comment">         that reduces the full dense Hermitian matrix to a
</span><span class="comment">*</span><span class="comment">         (reducible) symmetric tridiagonal matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDQ    (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The leading dimension of the array Q.  LDQ &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  IWORK  (workspace) INTEGER array,
</span><span class="comment">*</span><span class="comment">         the dimension of IWORK must be at least
</span><span class="comment">*</span><span class="comment">                      6 + 6*N + 5*N*lg N
</span><span class="comment">*</span><span class="comment">                      ( lg( N ) = smallest integer k
</span><span class="comment">*</span><span class="comment">                                  such that 2^k &gt;= N )
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  RWORK  (workspace) REAL array,
</span><span class="comment">*</span><span class="comment">                               dimension (1 + 3*N + 2*N*lg N + 3*N**2)
</span><span class="comment">*</span><span class="comment">                        ( lg( N ) = smallest integer k
</span><span class="comment">*</span><span class="comment">                                    such that 2^k &gt;= N )
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  QSTORE (workspace) COMPLEX array, dimension (LDQS, N)
</span><span class="comment">*</span><span class="comment">         Used to store parts of
</span><span class="comment">*</span><span class="comment">         the eigenvector matrix when the updating matrix multiplies
</span><span class="comment">*</span><span class="comment">         take place.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDQS   (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The leading dimension of the array QSTORE.
</span><span class="comment">*</span><span class="comment">         LDQS &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO   (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit.
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value.
</span><span class="comment">*</span><span class="comment">          &gt; 0:  The algorithm failed to compute an eigenvalue while
</span><span class="comment">*</span><span class="comment">                working on the submatrix lying in rows and columns
</span><span class="comment">*</span><span class="comment">                INFO/(N+1) through mod(INFO,N+1).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Warning:      N could be as big as QSIZ!
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      REAL               TWO
      PARAMETER          ( TWO = 2.E+0 )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      INTEGER            CURLVL, CURPRB, CURR, I, IGIVCL, IGIVNM,
     $                   IGIVPT, INDXQ, IPERM, IPRMPT, IQ, IQPTR, IWREM,
     $                   J, K, LGN, LL, MATSIZ, MSD2, SMLSIZ, SMM1,
     $                   SPM1, SPM2, SUBMAT, SUBPBS, TLVLS
      REAL               TEMP
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           CCOPY, <a name="CLACRM.95"></a><a href="clacrm.f.html#CLACRM.1">CLACRM</a>, <a name="CLAED7.95"></a><a href="claed7.f.html#CLAED7.1">CLAED7</a>, SCOPY, <a name="SSTEQR.95"></a><a href="ssteqr.f.html#SSTEQR.1">SSTEQR</a>, <a name="XERBLA.95"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      INTEGER            <a name="ILAENV.98"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
      EXTERNAL           <a name="ILAENV.99"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          ABS, INT, LOG, MAX, REAL
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input parameters.
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     IF( ICOMPQ .LT. 0 .OR. ICOMPQ .GT. 2 ) THEN
</span><span class="comment">*</span><span class="comment">        INFO = -1
</span><span class="comment">*</span><span class="comment">     ELSE IF( ( ICOMPQ .EQ. 1 ) .AND. ( QSIZ .LT. MAX( 0, N ) ) )
</span><span class="comment">*</span><span class="comment">    $        THEN
</span>      IF( QSIZ.LT.MAX( 0, N ) ) THEN
         INFO = -1
      ELSE IF( N.LT.0 ) THEN
         INFO = -2
      ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN
         INFO = -6
      ELSE IF( LDQS.LT.MAX( 1, N ) ) THEN
         INFO = -8
      END IF
      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.124"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="CLAED0.124"></a><a href="claed0.f.html#CLAED0.1">CLAED0</a>'</span>, -INFO )
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      IF( N.EQ.0 )
     $   RETURN
<span class="comment">*</span><span class="comment">
</span>      SMLSIZ = <a name="ILAENV.133"></a><a href="ilaenv.f.html#ILAENV.1">ILAENV</a>( 9, <span class="string">'<a name="CLAED0.133"></a><a href="claed0.f.html#CLAED0.1">CLAED0</a>'</span>, <span class="string">' '</span>, 0, 0, 0, 0 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Determine the size and placement of the submatrices, and save in
</span><span class="comment">*</span><span class="comment">     the leading elements of IWORK.
</span><span class="comment">*</span><span class="comment">
</span>      IWORK( 1 ) = N
      SUBPBS = 1
      TLVLS = 0
   10 CONTINUE
      IF( IWORK( SUBPBS ).GT.SMLSIZ ) THEN
         DO 20 J = SUBPBS, 1, -1
            IWORK( 2*J ) = ( IWORK( J )+1 ) / 2
            IWORK( 2*J-1 ) = IWORK( J ) / 2
   20    CONTINUE
         TLVLS = TLVLS + 1
         SUBPBS = 2*SUBPBS
         GO TO 10
      END IF
      DO 30 J = 2, SUBPBS
         IWORK( J ) = IWORK( J ) + IWORK( J-1 )
   30 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Divide the matrix into SUBPBS submatrices of size at most SMLSIZ+1
</span><span class="comment">*</span><span class="comment">     using rank-1 modifications (cuts).
</span><span class="comment">*</span><span class="comment">
</span>      SPM1 = SUBPBS - 1
      DO 40 I = 1, SPM1
         SUBMAT = IWORK( I ) + 1
         SMM1 = SUBMAT - 1
         D( SMM1 ) = D( SMM1 ) - ABS( E( SMM1 ) )
         D( SUBMAT ) = D( SUBMAT ) - ABS( E( SMM1 ) )
   40 CONTINUE
<span class="comment">*</span><span class="comment">
</span>      INDXQ = 4*N + 3
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Set up workspaces for eigenvalues only/accumulate new vectors
</span><span class="comment">*</span><span class="comment">     routine
</span><span class="comment">*</span><span class="comment">
</span>      TEMP = LOG( REAL( N ) ) / LOG( TWO )
      LGN = INT( TEMP )
      IF( 2**LGN.LT.N )
     $   LGN = LGN + 1
      IF( 2**LGN.LT.N )
     $   LGN = LGN + 1
      IPRMPT = INDXQ + N + 1
      IPERM = IPRMPT + N*LGN
      IQPTR = IPERM + N*LGN
      IGIVPT = IQPTR + N + 2
      IGIVCL = IGIVPT + N*LGN
<span class="comment">*</span><span class="comment">
</span>      IGIVNM = 1
      IQ = IGIVNM + 2*N*LGN
      IWREM = IQ + N**2 + 1
<span class="comment">*</span><span class="comment">     Initialize pointers
</span>      DO 50 I = 0, SUBPBS
         IWORK( IPRMPT+I ) = 1
         IWORK( IGIVPT+I ) = 1
   50 CONTINUE
      IWORK( IQPTR ) = 1
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Solve each submatrix eigenproblem at the bottom of the divide and
</span><span class="comment">*</span><span class="comment">     conquer tree.
</span><span class="comment">*</span><span class="comment">
</span>      CURR = 0
      DO 70 I = 0, SPM1
         IF( I.EQ.0 ) THEN
            SUBMAT = 1
            MATSIZ = IWORK( 1 )
         ELSE
            SUBMAT = IWORK( I ) + 1
            MATSIZ = IWORK( I+1 ) - IWORK( I )
         END IF
         LL = IQ - 1 + IWORK( IQPTR+CURR )
         CALL <a name="SSTEQR.206"></a><a href="ssteqr.f.html#SSTEQR.1">SSTEQR</a>( <span class="string">'I'</span>, MATSIZ, D( SUBMAT ), E( SUBMAT ),
     $                RWORK( LL ), MATSIZ, RWORK, INFO )
         CALL <a name="CLACRM.208"></a><a href="clacrm.f.html#CLACRM.1">CLACRM</a>( QSIZ, MATSIZ, Q( 1, SUBMAT ), LDQ, RWORK( LL ),
     $                MATSIZ, QSTORE( 1, SUBMAT ), LDQS,
     $                RWORK( IWREM ) )
         IWORK( IQPTR+CURR+1 ) = IWORK( IQPTR+CURR ) + MATSIZ**2
         CURR = CURR + 1
         IF( INFO.GT.0 ) THEN
            INFO = SUBMAT*( N+1 ) + SUBMAT + MATSIZ - 1
            RETURN
         END IF
         K = 1
         DO 60 J = SUBMAT, IWORK( I+1 )
            IWORK( INDXQ+J ) = K
            K = K + 1
   60    CONTINUE
   70 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Successively merge eigensystems of adjacent submatrices
</span><span class="comment">*</span><span class="comment">     into eigensystem for the corresponding larger matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     while ( SUBPBS &gt; 1 )
</span><span class="comment">*</span><span class="comment">
</span>      CURLVL = 1
   80 CONTINUE
      IF( SUBPBS.GT.1 ) THEN
         SPM2 = SUBPBS - 2
         DO 90 I = 0, SPM2, 2
            IF( I.EQ.0 ) THEN
               SUBMAT = 1
               MATSIZ = IWORK( 2 )
               MSD2 = IWORK( 1 )
               CURPRB = 0
            ELSE
               SUBMAT = IWORK( I ) + 1
               MATSIZ = IWORK( I+2 ) - IWORK( I )
               MSD2 = MATSIZ / 2
               CURPRB = CURPRB + 1
            END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Merge lower order eigensystems (of size MSD2 and MATSIZ - MSD2)
</span><span class="comment">*</span><span class="comment">     into an eigensystem of size MATSIZ.  <a name="CLAED7.247"></a><a href="claed7.f.html#CLAED7.1">CLAED7</a> handles the case
</span><span class="comment">*</span><span class="comment">     when the eigenvectors of a full or band Hermitian matrix (which
</span><span class="comment">*</span><span class="comment">     was reduced to tridiagonal form) are desired.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     I am free to use Q as a valuable working space until Loop 150.
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="CLAED7.253"></a><a href="claed7.f.html#CLAED7.1">CLAED7</a>( MATSIZ, MSD2, QSIZ, TLVLS, CURLVL, CURPRB,
     $                   D( SUBMAT ), QSTORE( 1, SUBMAT ), LDQS,
     $                   E( SUBMAT+MSD2-1 ), IWORK( INDXQ+SUBMAT ),
     $                   RWORK( IQ ), IWORK( IQPTR ), IWORK( IPRMPT ),
     $                   IWORK( IPERM ), IWORK( IGIVPT ),
     $                   IWORK( IGIVCL ), RWORK( IGIVNM ),
     $                   Q( 1, SUBMAT ), RWORK( IWREM ),
     $                   IWORK( SUBPBS+1 ), INFO )
            IF( INFO.GT.0 ) THEN
               INFO = SUBMAT*( N+1 ) + SUBMAT + MATSIZ - 1
               RETURN
            END IF
            IWORK( I / 2+1 ) = IWORK( I+2 )
   90    CONTINUE
         SUBPBS = SUBPBS / 2
         CURLVL = CURLVL + 1
         GO TO 80
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     end while
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Re-merge the eigenvalues/vectors which were deflated at the final
</span><span class="comment">*</span><span class="comment">     merge step.
</span><span class="comment">*</span><span class="comment">
</span>      DO 100 I = 1, N
         J = IWORK( INDXQ+I )
         RWORK( I ) = D( J )
         CALL CCOPY( QSIZ, QSTORE( 1, J ), 1, Q( 1, I ), 1 )
  100 CONTINUE
      CALL SCOPY( N, RWORK, 1, D, 1 )
<span class="comment">*</span><span class="comment">
</span>      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="CLAED0.286"></a><a href="claed0.f.html#CLAED0.1">CLAED0</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
